package bbb;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class J26_SungJuknewDate2 extends JDialog {
	private static J26_SungJuKservice2 sjsrv;
	private final JPanel contentPanel = new JPanel();
	private JTextField namelbl;
	private JTextField korlbl;
	private JTextField englbl;
	private JTextField matlbl;

	
	/**
	 * Create the dialog.
	 */
	public J26_SungJuknewDate2(JFrame p) {
		super(p);
		sjsrv = new J26_SungJuKservice2();
		setModalityType(ModalityType.DOCUMENT_MODAL);
		setTitle("새 성적 입력");
		setBounds(100, 100, 601, 377);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		GridBagLayout gbl_contentPanel = new GridBagLayout();
		gbl_contentPanel.columnWidths = new int[]{180, 0, 20, 0, 0};
		gbl_contentPanel.rowHeights = new int[]{100, 0, 0, 0, 0, 0};
		gbl_contentPanel.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_contentPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		contentPanel.setLayout(gbl_contentPanel);
		{
			JLabel name = new JLabel("이름");
			GridBagConstraints gbc_name = new GridBagConstraints();
			gbc_name.anchor = GridBagConstraints.EAST;
			gbc_name.insets = new Insets(0, 0, 5, 5);
			gbc_name.gridx = 1;
			gbc_name.gridy = 1;
			contentPanel.add(name, gbc_name);
		}
		{
			namelbl = new JTextField();
			GridBagConstraints gbc_namelbl = new GridBagConstraints();
			gbc_namelbl.insets = new Insets(0, 0, 5, 0);
			gbc_namelbl.fill = GridBagConstraints.HORIZONTAL;
			gbc_namelbl.gridx = 3;
			gbc_namelbl.gridy = 1;
			contentPanel.add(namelbl, gbc_namelbl);
			namelbl.setColumns(10);
		}
		{
			JLabel kor = new JLabel("국어");
			GridBagConstraints gbc_kor = new GridBagConstraints();
			gbc_kor.anchor = GridBagConstraints.EAST;
			gbc_kor.insets = new Insets(0, 0, 5, 5);
			gbc_kor.gridx = 1;
			gbc_kor.gridy = 2;
			contentPanel.add(kor, gbc_kor);
		}
		{
			korlbl = new JTextField();
			GridBagConstraints gbc_korlbl = new GridBagConstraints();
			gbc_korlbl.insets = new Insets(0, 0, 5, 0);
			gbc_korlbl.fill = GridBagConstraints.HORIZONTAL;
			gbc_korlbl.gridx = 3;
			gbc_korlbl.gridy = 2;
			contentPanel.add(korlbl, gbc_korlbl);
			korlbl.setColumns(10);
		}
		{
			JLabel eng = new JLabel("영어");
			GridBagConstraints gbc_eng = new GridBagConstraints();
			gbc_eng.anchor = GridBagConstraints.EAST;
			gbc_eng.insets = new Insets(0, 0, 5, 5);
			gbc_eng.gridx = 1;
			gbc_eng.gridy = 3;
			contentPanel.add(eng, gbc_eng);
		}
		{
			englbl = new JTextField();
			GridBagConstraints gbc_englbl = new GridBagConstraints();
			gbc_englbl.insets = new Insets(0, 0, 5, 0);
			gbc_englbl.fill = GridBagConstraints.HORIZONTAL;
			gbc_englbl.gridx = 3;
			gbc_englbl.gridy = 3;
			contentPanel.add(englbl, gbc_englbl);
			englbl.setColumns(10);
		}
		{
			JLabel mat = new JLabel("수학");
			GridBagConstraints gbc_mat = new GridBagConstraints();
			gbc_mat.anchor = GridBagConstraints.EAST;
			gbc_mat.insets = new Insets(0, 0, 0, 5);
			gbc_mat.gridx = 1;
			gbc_mat.gridy = 4;
			contentPanel.add(mat, gbc_mat);
		}
		{
			matlbl = new JTextField();
			GridBagConstraints gbc_matlbl = new GridBagConstraints();
			gbc_matlbl.fill = GridBagConstraints.HORIZONTAL;
			gbc_matlbl.gridx = 3;
			gbc_matlbl.gridy = 4;
			contentPanel.add(matlbl, gbc_matlbl);
			matlbl.setColumns(10);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						if(namelbl.getText().equals("") || korlbl.getText().equals("") || englbl.getText().equals("") || matlbl.getText().equals("")){
							JOptionPane.showMessageDialog(null, "누락된항목이있습니다~","오류발생",JOptionPane.ERROR_MESSAGE);
							return;
						}
								
						
						String nameval = namelbl.getText();
						int korval = Integer.parseInt(korlbl.getText());
						int engval = Integer.parseInt(englbl.getText());
						int matval = Integer.parseInt(matlbl.getText());
						String msg = nameval + "/" + korval + "/" + engval + "/" + matval; 
						JOptionPane.showMessageDialog(null, msg);
						
						J26_SungJukvo sj = new J26_SungJukvo();
						sj.setName(namelbl.getText());
						sj.setKor(korlbl.getText());
						sj.setEng(englbl.getText());
						sj.setMat(matlbl.getText());

						if(sjsrv.createSungJuk(sj))
							JOptionPane.showMessageDialog(null, "입력완료");
						else
							JOptionPane.showMessageDialog(null, "입력실패");
						
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						namelbl.setText("");
						korlbl.setText("");
						englbl.setText("");
						matlbl.setText("");
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
			setVisible(true);
		}
	}

}
